package com.zkq.graduate.service.impl;

import com.zkq.graduate.enums.DateTimeFormatterEnum;
import com.zkq.graduate.mapper.SelectedTitleMapper;
import com.zkq.graduate.pojo.StudentVo;
import com.zkq.graduate.service.SelectedTitleService;
import com.zkq.graduate.util.LocalDateTimeUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author zhangkaiqiang
 * @Date 2019/11/29  17:32
 * @Description TODO
 */
@Service("selectedTitleService")
public class SelectedTitleServiceImpl implements SelectedTitleService{

	@Resource
	private SelectedTitleMapper selectedTitleMapper;

	@Override
	public List<StudentVo> findStudentSelectedTitle(String studentId) {
		List<StudentVo> list=selectedTitleMapper.findStudentSelectedTitle(studentId);
		if(CollectionUtils.isEmpty(list)){
			return new ArrayList<>();
		}
		return list;
	}

	@Override
	public boolean insertOneSelectTitle(StudentVo studentVo) {
		String selectTime= LocalDateTimeUtil.formatLocalDateTime(LocalDateTime.now(), DateTimeFormatterEnum.YEAR_MONTH_DAY);
		studentVo.setSelectTime(selectTime);
		return selectedTitleMapper.insertOneSelectTitle(studentVo)==1;
	}

	@Override
	public List<StudentVo> listAllStudentByTeacher(String titleId) {
		List<StudentVo> list=selectedTitleMapper.listAllStudentByTeacher(titleId);
		if(CollectionUtils.isEmpty(list)){
			return new ArrayList<>();
		}
		return list;
	}

	@Override
	public boolean teacherPassStudentSelected(String[] ids) {
		if(ids!=null){
			return selectedTitleMapper.teacherPassStudentSelected(ids)==ids.length;
		}
		return false;
	}

	@Override
	public boolean teacherRejectStudentSelected(StudentVo studentVo){
		return selectedTitleMapper.teacherRejectStudentSelected(studentVo)==1;
	}
}
